package com.yl.auth.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.model.entity.HeZuoZuZhi;
import com.yl.auth.model.entity.TuiJianRen;
import com.yl.auth.model.vo.HeZuoZuZhiVo;
import com.yl.auth.service.HeZuoZuZhiService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.security.core.parameters.P;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author L
 * @since 2023-06-25
 */
@Api(tags = "市场销售-合作组织管理")
@RestController
@RequestMapping("/admin/yanglao/hezuozuzhi")
@CrossOrigin
public class HeZuoZuZhiController {

    @Resource
    private HeZuoZuZhiService heZuoZuZhiService;

    @ApiOperation("全查+分页+条件查询")
    @GetMapping("/findAllConAndPage/{page}/{limit}")
    public Result findAllConAndPage(@PathVariable @ApiParam("当前页") Integer page,
                                    @PathVariable @ApiParam("总条数") Integer limit,
                                    HeZuoZuZhiVo heZuoZuZhiVo){
        Page<HeZuoZuZhi> page1 = new Page<>(page,limit);
        Page<HeZuoZuZhi> heZuoZuZhiPage = heZuoZuZhiService.findAllConAndPage(page1,heZuoZuZhiVo);
        return Result.ok(heZuoZuZhiPage);
    }

    @ApiOperation("新增合作组织")
    @PostMapping("/save")
    public Result save(@RequestBody HeZuoZuZhi heZuoZuZhi){
        heZuoZuZhi.setIntegral(0L);
        heZuoZuZhi.setReference(0);
        heZuoZuZhi.setReward(0L);
        heZuoZuZhiService.save(heZuoZuZhi);
        return Result.ok();
    }
    @ApiOperation("根据Id获取指定合作组织信息")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Integer id){
        HeZuoZuZhi heZuoZuZhi = heZuoZuZhiService.getById(id);
        return Result.ok(heZuoZuZhi);
    }
    @ApiOperation("根据Id修改指定合作组织信息")
    @PostMapping("/update")
    public Result update(@RequestBody HeZuoZuZhi heZuoZuZhi){
        heZuoZuZhiService.updateById(heZuoZuZhi);
        return Result.ok();
    }

    @ApiOperation("根据Id删除指定合作组织信息")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        heZuoZuZhiService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("积分奖励设置")
    @PostMapping("/saveReward")
    public Result saveReward(@RequestBody HeZuoZuZhi heZuoZuZhi){
        heZuoZuZhiService.updateByReward(heZuoZuZhi);
        return Result.ok();
    }

    @ApiOperation("查询全部合作组织")
    @GetMapping("/findAllHeZuoZuZhi")
    public Result findAllHeZuoZuZhi(){
        List<HeZuoZuZhi> list = heZuoZuZhiService.list();
        return Result.ok(list);
    }
}


